Within software, control flow mechanisms help specify the order in which individual statements, instructions, calls, and other items are executed or evaluated. At the source code level, and sometimes at lower levels, different programming languages and different run-time environments may provide different control flow mechanisms.
At the level of machine or assembly language, control flow instructions often work by altering the program counter. Within source code, a given language may provide control flow statements which: continue execution at a location other than the following statement (e.g., unconditional branch, jump, goto); execute specified statements only if some condition is met (e.g., conditional branch); execute specified statements zero or more times depending on some specified condition (e.g., loop); execute a set of distant statements and then return to pick up where it left off (e.g., routines, functions, methods, coroutines); and/or unconditionally halt execution.
In many cases, the effects of a given control flow mechanism on a program's data can be obtained using any of several equivalent control flow mechanisms. Routine bodies may be inlined, for example, without changing the program's behavior as to data outputs for given inputs (although execution speed and/or memory requirements may change). Likewise, loops having an exit condition in the middle or at the end of a loop body can have functionally equivalent instruction sequences whose exit condition is tested at the top of a loop body. Control flow structures which have one entry and one exit are often easier to understand than those which do not, because (conceptually at least) such structures can be used anywhere in a program as a single statement without complicating the control flow. Such control flow structures are called “composable”. Many loops are composable structures, for example.